<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>阳光成单系统</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="./css/x-admin.css" media="all">
<body>
	<div class="x-body">
		<form class="layui-form" onsubmit="return false">
			<div class="layui-form-item">
				<label for="L_username" class="layui-form-label"> 用户 </label>
				<div class="layui-input-inline">
					<input type="text" id="L_username" name="username" disabled=""
						value="小明" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="L_repass" class="layui-form-label"> <span
					class="x-red">*</span>旧密码
				</label>
				<div class="layui-input-inline">
					<input type="" id="jiuMiMa" name="oldpass" required=""
						lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="L_pass" class="layui-form-label"> <span
					class="x-red">*</span>新密码
				</label>
				<div class="layui-input-inline">
					<input type="" id="miMa" name="newpass" required=""
						lay-verify="required" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-form-mid layui-word-aux">6到16个字符</div>
			</div>
			<div class="layui-form-item">
				<label for="L_repass" class="layui-form-label"> <span
					class="x-red">*</span>确认密码
				</label>
				<div class="layui-input-inline">
					<input type="" id="twoMiMa" name="repass" required=""
						lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="L_repass" class="layui-form-label"> </label>
				<button class="layui-btn" lay-filter="save" lay-submit="">
					保存</button>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
	<script src="layui/layui.js"></script>
	<script>
		var layer, form, $;
		layui.use([ 'form', 'layer' ], function() {
			$ = layui.$;
			form = layui.form;
			layer = layui.layer;
			
			
			var id = localStorage.getItem("uid");
			console.log(id);
			var uname = localStorage.getItem("uname");
			console.log(uname);
			
			if(uname != null){
				$("#L_username").val(uname);
			}
			
			$.post("selPsd",{
				Id:id
			},function(res){
				localStorage.clear();
				localStorage.setItem("psd",res.data.Password);
			},"json");
			
			var psd = localStorage.getItem("psd");
			console.log(psd);
			
			form.on('submit(save)', function(data) {
				if ($("#jiuMiMa").val()==psd) {
					if($("#miMa").val()==$("#twoMiMa").val()){
						$.post("modifyPassword",{
							Id:id,
							Password:$("#miMa").val()
						},function(res){
							console.log(res);
							if(res.code=="0"){
								layer.msg("修改成功");
								window.location.href="login.html";
							} else{
								layer.msg("修改失败");
							}
						},"json")
					}else {
						layer.msg("两次密码不一致");
					}
				} else {
					layer.msg("旧密码输入错误");
				}
				return false;
			});
        });
	</script>
</body>
</html>